package com.example.test01;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
  LayoutInflater inflater;
  LinearLayout view;
  Button btn_add;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inflater = LayoutInflater.from(this);
    view = (LinearLayout) findViewById(R.id.layout_view);

    final Button btn_add = (Button) findViewById(R.id.btn_add);
    btn_add.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        long count = 0;
        for (int j = 0; j < 100; j++) {
          view.removeAllViews();
          long begin = System.currentTimeMillis();
          for (int i = 0; i < 10; i++) {
            View vv = inflater.inflate(R.layout.item_menu_ago, view, false);
            view.addView(vv);
          }
          long end = System.currentTimeMillis();
          count += end - begin;
        }

        btn_add.setText("Time=" + count / 100f);
      }
    });


    final Button btn_add2 = (Button) findViewById(R.id.btn_add2);
    btn_add2.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        long count = 0;
        for (int j = 0; j < 100; j++) {
          view.removeAllViews();
          long begin = System.currentTimeMillis();
          for (int i = 0; i < 10; i++) {
            View vv = inflater.inflate(R.layout.item_menu_dynamic, view, false);
            view.addView(vv);
            ((ViewStub) vv.findViewById(R.id.vs_icon)).inflate();
            ((ViewStub) vv.findViewById(R.id.vs_title_bottom)).inflate();
            ((ViewStub) vv.findViewById(R.id.layout_menu_toggle)).inflate();

            ((ViewStub) vv.findViewById(R.id.layout_menu_title_tip)).inflate();
            ((ViewStub) vv.findViewById(R.id.layout_menu_right_txt)).inflate();
            ((ViewStub) vv.findViewById(R.id.layout_menu_right_res)).inflate();
          }
          long end = System.currentTimeMillis();
          count += end - begin;
        }

        btn_add2.setText("Time=" + count / 100f);
      }
    });


    final Button btn_add3 = (Button) findViewById(R.id.btn_add3);
    btn_add3.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        long count = 0;
        for (int j = 0; j < 100; j++) {
          view.removeAllViews();
          long begin = System.currentTimeMillis();
          for (int i = 0; i < 10; i++) {
            View vv = inflater.inflate(R.layout.item_menu_dynamic, view, false);
            view.addView(vv);
            ((ViewStub) vv.findViewById(R.id.vs_icon)).inflate();
            ((ViewStub) vv.findViewById(R.id.vs_title_bottom)).inflate();
            ((ViewStub) vv.findViewById(R.id.layout_menu_toggle)).inflate();
          }
          long end = System.currentTimeMillis();
          count += end - begin;
        }

        btn_add3.setText("Time=" + count / 100f);
      }
    });


    final Button btn_add4 = (Button) findViewById(R.id.btn_add4);
    btn_add4.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        long count = 0;
        for (int j = 0; j < 100; j++) {
          view.removeAllViews();
          long begin = System.currentTimeMillis();
          for (int i = 0; i < 10; i++) {
            View vv = inflater.inflate(R.layout.item_menu_new, view, false);
            view.addView(vv);
          }
          long end = System.currentTimeMillis();
          count += end - begin;
        }

        btn_add4.setText("Time=" + count / 100f);
      }
    });
  }
}
